package com.itfreer.data.sqlite;


import com.itfreer.data.general.GlobalDataType;
import com.itfreer.data.general.IDataTypeConvert;

/**
 * 类功能说明 定义结构表类型转换为Oracle数据库类型
 */
public class SqliteDataTypeConvert implements IDataTypeConvert {

	/**
	 * @Title: Convert
	 * @Description: 结构表数据类型转换
	 * @param @param dateType
	 * @param @return
	 * @throws
	 */
	public String Convert(GlobalDataType dateType) {
		String mySqlType = "";
		switch (dateType) {
		case Boolean:
			mySqlType = "SMALLINT(1)";
			break;
		case Char:
			mySqlType = "CHAR(1)";
			break;
		case String:
			mySqlType = "VARCHAR(254)";
			break;
		case Text:
			mySqlType = "LONGTEXT";
			break;
		case Date:
			mySqlType = "date";
			break;
		case DateTime:
			mySqlType = "datetime";
			break;
		case Decimal:
			mySqlType = "DECIMAL";
			break;
		case Double:
			mySqlType = "FLOAT";
			break;
		case Single:
			mySqlType = "REAL";
			break;
		case Int16:
		case UInt16:
		case UInt32:
		case Int32:
		case UInt64:
		case Int64:
			mySqlType = "INT";
			break;
		case ByteArray:
			mySqlType = "BLOB";
			break;
		case NoDefault:
			break;
		default:
			break;
		}
		return mySqlType;
	}

	// 数据类型转换
	public GlobalDataType Convert(String dateType) {
		GlobalDataType gType = GlobalDataType.NoDefault;
		dateType = dateType.toUpperCase();
		if ("SMALLINT(1)".equals(dateType)) {
			gType = GlobalDataType.Boolean;
		} else if ("CHAR(1)".equals(dateType) || "CHAR".equals(dateType)) {
			gType = GlobalDataType.Char;
		} else if ("NVARCHAR2(254)".equals(dateType)
				|| "STRING".equals(dateType) || "NVARCHAR2".equals(dateType)
				|| "VARCHAR".equals(dateType)) {
			gType = GlobalDataType.String;
		} else if ("NCLOB".equals(dateType) || "LONGTEXT".equals(dateType)
				|| "TEXT".equals(dateType)) {
			gType = GlobalDataType.Text;
		} else if ("DATE".equals(dateType) || "DATETIME".equals(dateType)
				|| "TIMESTAMP".equals(dateType)) {
			gType = GlobalDataType.DateTime;
		} else if ("DECIMAL".equals(dateType)) {
			gType = GlobalDataType.Decimal;
		} else if ("FLOAT".equals(dateType) || "DOUBLE".equals(dateType)) {
			gType = GlobalDataType.Double;
		} else if ("REAL".equals(dateType)) {
			gType = GlobalDataType.Single;
		} else if ("INTEGER".equals(dateType) || "NUMBER".equals(dateType) 
				|| "INT".equals(dateType) || "TINYINT".equals(dateType)
				|| "BIGINT".equals(dateType) || "SMALLINT".equals(dateType)) {
			gType = GlobalDataType.Int32;
		} else if ("LONG RAW".equals(dateType) || "BLOB".equals(dateType)
				|| "LONGBLOB".equals(dateType)) {
			gType = GlobalDataType.ByteArray;
		} else {
			if (dateType.indexOf("NVARCHAR2") != -1
					|| dateType.indexOf("VARCHAR2") != -1
					|| dateType.indexOf("NVARCHAR") != -1
					|| dateType.indexOf("VARCHAR") != -1) {
				gType = GlobalDataType.String;
			}
		}
		if(gType == GlobalDataType.NoDefault){
			System.out.println(dateType+" [NoDefault] ");
		}
		return gType;
	}
}